package com.onlyphoto.onlymall.bean

import com.onlyphoto.onlymall.base.BaseEntity
import com.onlyphoto.onlymall.interfaces.UIProgressListener


class SelectPicBean : BaseEntity() {

    var url: String? = null
    var progress: Int = 0
    var type: Int = 0
    var picName: String? = null
    var id: String? = null


    val uiProgressListener: UIProgressListener = object : UIProgressListener() {


        override fun onUIFinish(currentBytes: Long, contentLength: Long, done: Boolean) {

        }

        override fun onUIProgress(currentBytes: Long, contentLength: Long, done: Boolean) {
            val percent = (currentBytes * 100 / contentLength).toInt()
            progress = percent
            if (onRefreshCallBack != null)
                onRefreshCallBack!!.onRefresh()
        }

        override fun onSuccess(msg: String) {}

        override fun onFailed(exception: Exception) {}
    }

    private var onRefreshCallBack: OnRefreshCallBack? = null

    fun setOnRefreshCallBack(callBack: OnRefreshCallBack) {
        onRefreshCallBack = callBack
    }

    interface OnRefreshCallBack {
        fun onRefresh()
    }

    companion object {

        const val Type_None = 0          // 显示图片
        const val Type_Add = 1           // 显示添加
        const val Type_Uploaded = 2      //上传完成
        const val Type_Uploading = 3     //上传中
        const val Type_UploadFailed = 4  //上传失败
    }
}